import { defineStore } from 'pinia';

export const useUserStore = defineStore('userInfo', {
	state: () => {
		return { 
			user: {},
		};
	},
	getters: {
		getUser(state) {
			const u = state.user.token?state.user:(localStorage.getItem('user')?JSON.parse(localStorage.getItem('user')):{})
			return u
		},
	},
	actions: {
		setUser(user_data) {
			this.user = user_data;
			localStorage.setItem("user", JSON.stringify(user_data))
		},
	},
});
